package test;

import java.util.Random;

public class Role {
    private String name;
    private int blood;
    private char gender;
    private String face;

    public char getGender() {
        return gender;
    }

    public void setGender(char gender) {
        this.gender = gender;
    }

    public String getFace() {
        return face;
    }
    public Role(){}
    public Role(String name, int blood,char gender) {
        this.name = name;
        this.blood = blood;
        this.gender = gender;
        setFace(gender);
    }

    public void setFace(char face) {
        Random r=new Random();

        if(gender=='男'){
            int index=r.nextInt(boyfaces.length);
            this.face=boyfaces[index];
        }
        else if(gender=='女'){
            int index=r.nextInt(girlfaces.length);
            this.face=girlfaces[index];
        }
        else {
            this.face="面目狰狞";
        }
    }


    String[] boyfaces={"风流倜傥","气宇轩昂","相貌英俊","五官端正","相貌平平","一塌糊涂","面目狰狞"};
    String[] girlfaces={"美轮美奂","沉鱼落雁","亭亭玉立","五官端正","相貌平平","一塌糊涂","面目狰狞"};

    public String[] getBoyfaces() {
        return boyfaces;
    }
    public void setBoyfaces(String[] boyfaces) {
        this.boyfaces = boyfaces;
    }




    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public int getBlood() {
        return blood;
    }
    public void setBlood(int blood) {
        this.blood = blood;
    }

    //定义一个方法用于攻击别人
    //
    public void attack(Role role){
        //计算造成的伤害1~20
        Random r=new Random();
        int hurt=r.nextInt(20)+1;

        //剩余血量
        int remainBlood=role.getBlood()-hurt;
        remainBlood=remainBlood>0?remainBlood:0;

        //修改一下挨揍的人的血量
        role.setBlood(remainBlood);
        //this表示方法的调用者
        System.out.println(this.getName()+"举起拳头，打了"+role.getName()+"一下，"+"造成了"+hurt+"点伤害，鸠摩智还剩下了"+remainBlood+"点血");
    }

    public  void showRoleInfo(){
        System.out.println("姓名为："+getName());
        System.out.println("血量为："+getBlood());
        System.out.println("性别为："+getGender());
        System.out.println("长相为："+getFace());
    }
}
